-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8365919: Replace currentTimeMillis with nanoTime in Stresser.java #26879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back ayang! A progress list of the required criteria for merging this PR into |
@albertnetymk This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 17 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
@albertnetymk To determine the appropriate audience for reviewing this pull request, one or more labels corresponding to different subsystems will normally be applied automatically. However, no automatic labelling rule matches the changes in this pull request. In order to have an "RFR" email sent to the correct mailing list, you will need to add one or more applicable labels manually using the /label pull request command. Applicable Labels
|
/cc hotspot-gc |
@albertnetymk |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to load (options.getTime() * 1000) into a local rather than compute it multiple times.
Extracted that to a local var for |
@@ -179,15 +181,15 @@ public void printStressInfo(PrintStream out) { | |||
*/ | |||
public void printExecutionInfo(PrintStream out) { | |||
println(out, "Completed iterations: " + iterations); | |||
println(out, "Execution time: " + (currentTime - startTime) + " seconds"); | |||
println(out, "Execution time: " + (currentTime - startTime)/1000.0 + " seconds"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be spaces around the operator. The change sometimes has them and sometimes not.
println(out, "Execution time: " + (currentTime - startTime)/1000.0 + " seconds"); | |
println(out, "Execution time: " + (currentTime - startTime) / 1000.0 + " seconds"); |
@@ -318,11 +317,12 @@ public long getExecutionTime() { | |||
* @return time | |||
*/ | |||
public long getTimeLeft() { | |||
long current = System.currentTimeMillis(); | |||
if (current >= finishTime) { | |||
long elapsedTime = System.nanoTime()/1000000 - startTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could maybe use getExecutionTime()
? Also the repeated use of the term System.nanoTime() / 1000000
five time definitely warrants a helper function imo, and allows documentation of the reason for its use.
} else { | ||
finishTime = startTime + stressTime * 1000; | ||
} | ||
startTime = System.nanoTime()/1000000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the reason for the change is to use System.nanoTime()
instead of System.currentTimeMillis()
because of monoticity, wouldn't it be simpler to add a helper that returns a millisecond value based on System.nanoTime()
and call that one instead of System.currentTimeMillis()
and keep everything else the same?
Inlining the System.nanoTime() / 1000000
statement a few times seems bad. Having a helper function for this might allow to include a comment why System.currentTimeMillis()
is not used too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or use nanoTime resolution throughout the calculations and only normalize on printout and when comparing with the deadline. Although nanoTime is here not used for its resolution, I find it quite unusual to see that /1_000_000 sprinkled around the start time recording.
if (startTime == 0) { | ||
throw new TestBug("Stresser is not started."); | ||
} | ||
return !forceFinish | ||
&& !finished | ||
&& (maxIterations == 0 || iterations < maxIterations) | ||
&& (finishTime == 0 || currentTime < finishTime); | ||
&& (options.getTime() == 0 || (currentTime - startTime) < options.getTime() * 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt that inlining options.getTime() * 1000
literally 10 times instead of storing it in a local (finishTime
) or having a getter makes the code easier to understand.
Maybe just rename finishTime
to sth like stressTime
?
I have changed to use nanoseconds for all fields, to avoid excessive unit conversion. |
Mostly a mechanic change from
currentTimeMillis()
tonanoTime()/1000000
. It also removesfinishTime
to avoid overflowing.The change in
iteration()
is to ensurecurrentTime
is properly initialized.(Was investigating a timeout on Windows-x64, which led me to this code. I think this fix is good enough by its own.)
Test: tier1-5
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26879/head:pull/26879
$ git checkout pull/26879
Update a local copy of the PR:
$ git checkout pull/26879
$ git pull https://git.openjdk.org/jdk.git pull/26879/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26879
View PR using the GUI difftool:
$ git pr show -t 26879
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26879.diff
Using Webrev
Link to Webrev Comment